const app = getApp()

const baseURL = 'http://localhost:8080/'

/**
 * 接口请求封装
 */
function wxRequest(url, data, method = 'POST') {
    let token = wx.getStorageSync('token');
    return new Promise(function (resolve, reject) {
      wx.request({
        url: baseURL + url,
        data: data,
        method: method,
        header: {
          "Content-Type": "application/json;charset=UTF-8",
          "tokenMiniAPP": token ? token : ''
        },
        success(res) {
            resolve(res.data)
        },
        fail(err) {
          wx.showToast({
            icon: 'none',
            title: "网络连接失败！",
            duration: 2000
          })
          reject(err)
        }
      })
    })
  }

  module.exports = {
    wxRequest: wxRequest
  }